package lol.clann.minecraft.springboot.api.model.reflect;

import com.ruoshui.utils.java.exception.ExceptionUtils;
import lombok.Getter;

import java.lang.reflect.Field;

/**
 *
 * @author pyz
 * @date 2019/5/2 10:37 PM
 */
public class FieldInvoker {
    @Getter
    protected final Field field;

    public FieldInvoker(Field field) {
        this.field = field;
        field.setAccessible(true);
    }

    public Object get(Object target) {
        try {
            return field.get(target);
        } catch (IllegalAccessException e) {
            ExceptionUtils.throwException(e);
            return null;
        }
    }

    public void set(Object target, Object value) {
        try {
            field.set(target, value);
        } catch (IllegalAccessException e) {
            ExceptionUtils.throwException(e);

        }
    }
}
